export default{
    namespaced: true,
    state: {
        products:[]
    },
    mutations: {
        SET_PRODUCT(state,payload){
            state.products = payload
        },
        DECREASE_INVENTORY(state,payload){
            let target = state.products.find(item=>item.id===payload.id)
            if(target){
                target.inventory--
            }
        },
        DECREASE_PRODUCT(state,payload){
            let target = state.products.find(item=>item.id===payload.id)
            if(target){
                target.inventory++
            }
        }
    },
    actions: {
        async  FETCH_PRODUCT({commit}){
           let res = await fetch("http://chst.vip/data/index.json").then(body=>body.json())
            console.log(res);
            commit('SET_PRODUCT',res.data)
        }
        
    },
    modules: {},
    getters: {},

}